package com.xx.cloud.pay.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.cloud.pay.config.whitelist.IPWhitelist;
import com.xx.cloud.pay.entity.User;
import com.xx.cloud.pay.mapper.UserMapper;
import com.xx.cloud.pay.result.R;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class TestContropller {


    @Autowired
    UserMapper userMapper;

    @PostMapping("ok")
    public R getOk(@RequestBody @Valid User user) {

//        User user = new User()
//                .setName("张三");

        Page page = new Page<>(0, 10);
        Page selectPage = userMapper.selectPageJoin(page, user);

        System.out.println(selectPage.toString());
        System.out.println(selectPage.getRecords().toString());
        return R.ok(selectPage);

    }




    @IPWhitelist
    @PostMapping("oks")
    public R getOk1(@RequestBody  User user) {
        System.out.println(user);
//        String jsonString = JSONObject.toJSONString(user.getJson());
//        user.setJson(jsonString);
        userMapper.insert(user);
        return R.ok(user);

    }


    /**
     * 白名单库的IP参能访问
     * @return
     */
    @IPWhitelist
    @PostMapping("ok1")
    public R ok() {
        return R.ok("ok");
    }


    /**
     * 白名单库的IP参能访问
     * @return
     */
    @PostMapping("Test2")
    public R Test2() {
        System.out.println("压力测试");
        return R.ok("ok");
    }

}
